package com.jml.Lock;


/**
 *
 */
public class Wait {

    public static String a ="xx";

    public static void main(String[] args) throws InterruptedException {
        Sy1 s1 = new Sy1();
        s1.start();
        Thread.sleep(100);
        Sy1 s2 = new Sy1();
        s2.start();
        Thread.sleep(1000);
        Sy1 s3 = new Sy1();
        s3.start();
        Thread.sleep(1000);
        Sy1 s4 = new Sy1();
        s4.start();
        Thread.sleep(1000);
        synchronized (a){
            a.notify();
            Thread.sleep(500);
            System.out.println("huanx1");
        }
        //Thread.sleep(1000);
        synchronized (a){
            a.notify();
            Thread.sleep(500);
            System.out.println("huanx2");
        }
        //Thread.sleep(1000);
        synchronized (a){
            a.notify();
            Thread.sleep(500);
            System.out.println("huanx3");
        }
        //Thread.sleep(1000);
        synchronized (a){
            a.notify();
            Thread.sleep(500);
            System.out.println("huanx3");
        }
    }

    public static class Sy1 extends Thread{
        @Override
        public void run() {
            synchronized (a){
                System.out.println(Thread.currentThread().getName()+" begin");
                try {
                    a.wait();
                    System.out.println(Thread.currentThread().getName()+" end");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static class Sy2 extends Thread{
        @Override
        public void run() {
            synchronized (a){
                System.out.println(Thread.currentThread().getName()+" begin");
                try {
                    a.wait();
                    System.out.println(Thread.currentThread().getName()+" end");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static class Sy3 extends Thread{
        @Override
        public void run() {
            synchronized (a){
                System.out.println(Thread.currentThread().getName()+" begin");
                try {
                    a.wait();
                    System.out.println(Thread.currentThread().getName()+" end");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static class Sy4 extends Thread{
        @Override
        public void run() {
            synchronized (a){
                System.out.println(Thread.currentThread().getName()+" begin");
                try {
                    a.wait();
                    System.out.println(Thread.currentThread().getName()+" end");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }


}
